import java.awt.AWTException;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.io.File;
import javax.swing.filechooser.FileSystemView;


public class Application {
	
	private static RobotWindow window;
	private static ImageManager imageManager;
	private static Solver solver;
	private static MouseRobot mouseRobot;
	
	private static File homeDirectory;
	private static File desktopDirectory;

	public static void main(String[] args) {
		homeDirectory = FileSystemView.getFileSystemView().getHomeDirectory();
		desktopDirectory = FileSystemView.getFileSystemView().createFileObject(homeDirectory, "Desktop");
		window = new RobotWindow();
		window.setVisible(true);
		imageManager = new ImageManager();
		new Thread(solver = new Solver()).start();
		try { mouseRobot = new MouseRobot(); } catch (AWTException e) { e.printStackTrace(); }
		if(mouseRobot != null)
			new Thread(mouseRobot).start();
	}
	
	public static RobotWindow GetWindow() {
		return window;
	}
	
	public static Solver GetSolver() {
		return solver;
	}
	
	public static MouseRobot GetMouseRobot() {
		return mouseRobot;
	}
	
	public static ImageManager GetImageManager() {
		return imageManager;
	}
	
	public static Dimension GetScreenSize() {
		return Toolkit.getDefaultToolkit().getScreenSize();
	}

	public static File GetDesktopDirectory() {
		return desktopDirectory;
	}
	
	public static void StartSolving() {
		if(imageManager.gameGridRect == null) {
			imageManager.CaptureScreen();
			imageManager.DetectGameFrame();
		}
		solver.doSolve = true;
	}
	
	public static void StopSolving() {
		mouseRobot.active = false;
		solver.doSolve = false;
		window.ResetSolvingButton();
	}
	
	public static boolean IsSolving() {
		return solver.doSolve || mouseRobot.active;
	}

}
